<?php
class core_model_article extends core_model{
	/**
	 * 设置主健名称
	 */
	public function primarykey(){
		return "aid";
	}

	/**
	 * 设置当前表名
	 */
	public function tableName(){
		return core_lib_constant::TABLE_PRE."article";
	}
	
	function edit($data){
		if(!$this->_pkid) return false;
		if($data['title']) $this->set('title', $data['title']);
		if($data['from']) $this->set('from', $data['from']);
		if($data['views']) $this->set('views', $data['views']);
		if($data['content']) $this->set('content', $data['content']);
		return $this->save();
	}
	
	function create($data){
		if(!$data['title'] or !$data['content']){
			$this->setError(0, '缺少参数');
			return false;
		}
		if($data['title']) $this->set('title', $data['title']);
		if($data['from']) $this->set('from', $data['from']);
		if($data['views']) $this->set('views', intval($data['views']));
		if($data['content']) $this->set('content', $data['content']);
		$this->set('ip', Qutil::getIP());
		$this->set('create_time', $this->_time);
		return $this->save();
	}
}